package com.wanshi.servlet;

import com.wanshi.dao.UserDao;
import com.wanshi.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/delBatch")
public class DelBatchServlet extends HttpServlet {

    private UserService userService = new UserService();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        response.setContentType("text/html;charset=utf-8");
        String[] ids = request.getParameterValues("ids");

        //delete from user where id in(1,2,3);
        /*for(String id:ids){
            userDao.delUser(id);
        }*/
        if(ids == null || ids.length == 0){
            response.getWriter().write("您没有选择要删除的用户!");
            return;
        }
        userService.deleteBatch(ids);

        response.sendRedirect(request.getContextPath()+"/list");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}

